package com.choosefine.it.worker;

import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;

import java.util.HashMap;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.choosefine.it.worker.dao.FindWorkMapper;
import com.choosefine.it.worker.model.FindWork;
import com.choosefine.it.worker.model.vo.FindWorkVO;
import com.choosefine.it.worker.service.FindWorkService;

/**
 * Comments：
 * Author：yuxin
 * Create Date：2017/2/23/0023
 * Modified By：
 * Modified Date：
 * Why & What is modified：
 * Version：v1.0
 */
@RunWith(SpringJUnit4ClassRunner.class)
public class FindWorkServiceTestCase {
    @InjectMocks
    FindWorkService findWorkService;
    @Mock
    FindWorkMapper findWorkMapper;
    @Mock
    MongoTemplate mongoTemplate;
    @Before
    public void setUp(){
        MockitoAnnotations.initMocks(this);
    }
    /** 
     * @Description：根据id查看工人发布找工作信息pqq
     * @Author：yuxin
     * @Create Date：2017/2/23/0023
     * @param：
     * @return：
     */
    @Test
    public void should_selectByPrimaryKey_success()throws Exception{
        FindWork findWorkDb=new FindWork();
        FindWork findWorkNo=new FindWork();
      /*  when(findWorkMapper.getStatusflag(Mockito.anyMap())).thenReturn(1);*/
        when(findWorkMapper.selectByPrimaryKey(Mockito.anyInt())).thenReturn(findWorkDb);
        when(mongoTemplate.findOne(any(Query.class),eq(FindWork.class))).thenReturn(findWorkNo);
        FindWorkVO findWork=new FindWorkVO();
        findWork.setFindWork(findWorkNo);
        findWork.setIsInsert(1);
        FindWorkVO findWork1=findWorkService.selectByPrimaryKey(new HashMap());
        assertTrue(findWork1.getFindWork() != null);
        assertTrue(null!=findWork1.getIsInsert());
    }

    @Test
    public void should_select_by_primary_key_error()throws Exception{
        FindWork findWorkNo=new FindWork();
        /*when(findWorkMapper.getStatusflag(Mockito.anyMap())).thenReturn(1);*/
        when(findWorkMapper.selectByPrimaryKey(Mockito.anyInt())).thenReturn(null);
        when(mongoTemplate.findOne(any(Query.class),eq(FindWork.class))).thenReturn(findWorkNo);
        FindWorkVO findWork=new FindWorkVO();
        findWork.setFindWork(findWorkNo);
        findWork.setIsInsert(1);
        FindWorkVO findWork1=findWorkService.selectByPrimaryKey(new HashMap());
        assertTrue(null==findWork1);
    }
}
